package game.renderer.Denis;

import game.handler.implement.gameGameController;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;

public class MyJFrame extends JFrame implements KeyListener {

	final static int MAXX = 16;
	final static int MAXY = 8;
	
	private static final long serialVersionUID = 1L;
	BufferedImage bi;
	static gameGameController myController;
	
	public MyJFrame(gameGameController contr) {
		myController = contr;
		setSize(MAXX * 64 + 40, MAXY * 64 + 60);
		setUndecorated(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
		setResizable(false);
		setBackground(Color.BLACK);
 
		createBufferStrategy(2);
		
		addKeyListener(this);
	}
	
	public BufferedImage getPaintImage() {
		bi = new BufferedImage(MAXX * 64 + 40, MAXY * 64 + 60, BufferedImage.TYPE_INT_ARGB);
		return  bi;
	}
    
    public void paint(Graphics g){
    	g.drawImage(bi, 0, 0, MAXX * 64 + 40, MAXY * 64 + 60, null);
    } 
    
    public void setGameController(gameGameController contr) {
    	myController = contr;
    }

	@Override
	public void keyPressed(KeyEvent arg0) {
		myController.keyPressed(arg0);
	}

	@Override
	public void keyReleased(KeyEvent arg0) {
		myController.keyReleased(arg0);
	}

	@Override
	public void keyTyped(KeyEvent arg0) {
		// nothing
	}

}
